<template>
  <div id="app">
    <nav>
      <p id="user">
        <router-link to="/home">主页</router-link>
                  <input v-model="input" placeholder="输入搜索内容">
          <el-button type="primary" icon="el-icon-search" @click="search">搜索</el-button>
          <el-radio v-model="radio" label="1">全文匹配</el-radio>
          <el-radio v-model="radio" label="2">关键字匹配</el-radio>
         |
        <router-link to="/login" v-if="isLogin==false">登录</router-link>
        <router-link to="/register" v-if="isLogin==false">注册</router-link>
        <router-link :to="{path:'/space',query:{user_id:this.$store.state.user_id}}" v-if="isLogin==true">{{username}}</router-link>
        <router-link :to="{path:'/space',query:{user_id:this.$store.state.user_id}}" v-if="isLogin==true"><img :src="head_src"></router-link>
        <router-link to="/edit"><el-button type="primary">创作</el-button></router-link>
      </p>
    </nav>
    <router-view/>
  </div>
</template>

<script>
import { mapState,mapGetters,mapMutations,mapActions } from 'vuex'
export default {
  name: 'App',
    data(){
    return{
      radio: "1",
      input:''
    }
  },
  components: {

  },
  computed:{
    ...mapState(['isLogin','username','head_src']),
    ...mapGetters([]),
  },
  methods:{
    //使用映射函数映射的mutations方法，方法名必须和mutations中定义的方法相同
    //方法必须传递参数
    ...mapMutations([]),
    ...mapActions([]),
    search(){
      if(this.input==''){
        alert("请输入搜索内容！");
      }
      else{
        this.$router.push({path:"/result",query:{search:this.input,way:this.radio}});
        this.$store.state.input_search=this.input;
        this.$store.state.searchway=this.radio;
      }
    },
  }
}
</script>

<style scoped lang="scss">
*{
  margin:0;
  padding:0;
  list-style:none;
  text-decoration: none;
}
#app {
  margin:10px;
  padding:10px;
  img{
    position: relative;
    top:10px;
    width:40px;
    height:40px;
    border-radius: 100%;
  }
}

nav {
  padding: 10px;
  text-align: right;
  width:100%;
  #user{
    position:fixed;
    width:2000px;
    height:60px;
    right:0px;
    top:0px;
    z-index: 10;
    background:white;
  }
  input{
    width:300px;
    height:30px;
  }
  a {
    font-weight: bold;
    color: #2c3e50;
    padding:0 10px;
    &.router-link-exact-active {
      color: #42b983;
    }
  }
}
router-view{
  top:80px;
}
.page-enter-active{
  transition: all 0.5s;
}
.page-enter  {
  transform:translateX(10px);
  opacity: 0; //淡出效果
}

</style>
